var page_mask = document.getElementById("ui-view-29");   			//防弹层
var paybar = document.getElementById("js_paybar_wrap");               //支付栏
var paybar_prices = paybar.getElementsByClassName("pay-inblock")[0];
var paybar_price = paybar_prices.getElementsByTagName("b")[0];         //支付栏支付金额
var room_price = parseInt(paybar_price.innerHTML);                     //每间房的价格
var msg = document.getElementById("ui-view-13");                      //信息修改页面
var msg_intime = msg.getElementsByClassName("bk-fn17 js_inday_main_title")[0];//信息修改入住日期
var msg_intime_xq = msg.getElementsByClassName("bk-color5 js_inday_sub_title")[0];//信息修改入住星期
var msg_outtime = msg.getElementsByClassName("bk-color5 js_outday_sub_title")[0];//信息修改离店日期
var msg_tip = document.getElementById("ui-view-17")	                //信息修改提示页面
var msg_tip_price = msg_tip.getElementsByClassName("bk-color5")[0];   //信息修改价格提示
var msg_tip_ok = msg_tip.getElementsByClassName("cui-flexbd cui-btns-ok")[0];//信息修改提示确定按钮
var change_msg = document.getElementsByClassName("bk-color2")[0];     //修改信息按钮
var user_konw = document.getElementById("js_cancelPolicyInfo");       //用户须知按钮
var user_page = document.getElementById("ui-view-23");                //用户须知页面
var close_user_page = document.getElementsByClassName("font-g-close")[0];//关闭用户页面
var user_page_mask = document.getElementsByClassName("scroll-mask-layer js_scroll_mask animated animated1 fadeIn")[0];
var drop_btn = document.getElementById("ui-view-6"); 					//下拉按钮
var drop_room = document.getElementById("ui-view-7"); 			    //下拉房间
var exit_page_btn = document.getElementsByClassName("cm-header-icon fl js_back")[0];  //推出页面按钮
var exit_page = document.getElementById("ui-view-11");						//推出提示页面
var continue_btn = document.getElementsByClassName("cui-flexbd cui-btns-cancel")[0]; //继续按钮
var exit_btn = document.getElementsByClassName("cui-flexbd cui-btns-ok")[0];    //离开按钮
var off = false;
var rooms = 1;   //默认房间数是1
var show_day = document.getElementsByClassName("bk-fn17 js_outday_main_title")[0];//显示位置
var add_day = document.getElementsByClassName("cm-adjust-plus js_num_plus ")[0]; //添加按钮
var cut_day = document.getElementsByClassName("cm-adjust-minus js_num_minus  disabled  ")[0];//减少按钮
var decide_day_btn = document.getElementsByClassName("io-btn js_submit")[0];   //确定天数按钮
var day_msg = document.getElementById("js_checkInOutDay");           //住房信息
var day_msg_detail = day_msg.querySelectorAll("em");				 //订单具体信息
var room_num = document.getElementsByClassName("m-txt")[0];          //显示房间数量
var room_control = document.getElementById("ui-view-7");             //下拉控件
var room_control_num = room_control.querySelectorAll("span");

//获取首页传过来的数据
/*var str=window.location.search;*/ //从？开始后面的字符串
// var str=self.location.href;     //获取上面传来的参数
// var p=decodeURI(str);   	//解码
// var s=p.split("?");
// var get_date=JSON.parse(s[1])[0];  //获取传过来的日期
// var get_intime=get_date.intime;    //入住日期
// var get_outtime=get_date.outtime;	//离店日期


var get_intime = getQueryString("indate");
var get_outtime = getQueryString("outdate");
var get_between = daysBetween(get_intime, get_outtime); //日期差
console.log(get_intime, get_outtime);

//获取url参数
function getQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
    var reg_rewrite = new RegExp("(^|/)" + name + "/([^/]*)(/|$)", "i");
    var r = window.location.search.substr(1).match(reg);
    var q = window.location.pathname.substr(1).match(reg_rewrite);
    if (r != null) {
        return unescape(r[2]);
    } else if (q != null) {
        return unescape(q[2]);
    } else {
        return null;
    }
}

//初始化支付页面
init();

function init() {
    var i = get_intime.split("/");
    var o = get_outtime.split("/");

    function enter_date(i) {
        return "入住：" + i[1] + "月" + i[2] + "日";
    }

    function exit_date(o) {
        return "离店：" + o[1] + "月" + o[2] + "日";
    }

    day_msg_detail[0].innerHTML = enter_date(i);
    day_msg_detail[1].innerHTML = exit_date(o);
    day_msg_detail[2].innerHTML = get_between + "晚";
    show_day.innerHTML = "住" + get_between + "晚";
    paybar_price.innerHTML = room_price * get_between * rooms;   //金额
    msg_intime.innerHTML = i[1] + "月" + i[2] + "日";
    msg_intime_xq.innerHTML = "(" + xq(get_intime) + ")";  //入住星期
    msg_outtime.innerHTML = o[1] + "月" + o[2] + "日" + "(" + xq(get_outtime) + ")";
}

/*关闭所有副业面*/
function close_all() {
    page_mask.style.display = "none";
    msg.style.display = "none";
    exit_page.style.display = "none";
    msg_tip.style.display = "none";
}

/*点击防弹层*/
page_mask.onclick = function () {
    close_all();
}

/*下拉房间*/
drop_btn.onclick = function () {
    if (off) {
        drop_room.style.display = "none";
        off = !off
    } else {
        drop_room.style.display = "";
        off = !off;
    }
    for (var i = 0; i < room_control_num.length; i++) {
        room_control_num[i].index = i + 1;
        room_control_num[i].onclick = function () {
            room_num.innerHTML = this.index + "间";
            rooms = this.index;
            paybar_price.innerHTML = room_price * get_between * rooms;
            for (var i = 0; i < room_control_num.length; i++) {
                room_control_num[i].className = "item";
            }
            this.className = "item current";
        }
    }
}

//修改信息
change_msg.onclick = function () {
    msg.style.display = "block";
    page_mask.style.display = "block";
    //添加天数
    add_day.onclick = function () {
        get_between++;
        var s = next_days(get_intime, get_between);  //取得添加天数后的日期
        var n = s.split("/");
        show_day.innerHTML = "住" + get_between + "晚";
        if (n[1].length == 1) {
            msg_outtime.innerHTML = "0" + n[1] + "月" + n[2] + "日" + "(" + xq(next_days(get_intime, get_between)) + ")";
        } else {
            msg_outtime.innerHTML = n[1] + "月" + n[2] + "日" + "(" + xq(next_days(get_intime, get_between)) + ")";
        }
    }
    //减少天数
    cut_day.onclick = function () {
        if (get_between == 1) {
            return;
        }
        get_between--;
        var s = next_days(get_intime, get_between);  //取得减少天数后的日期
        var n = s.split("/");
        show_day.innerHTML = "住" + get_between + "晚";
        if (n[1].length == 1) {
            msg_outtime.innerHTML = "0" + n[1] + "月" + n[2] + "日" + "(" + xq(next_days(get_intime, get_between)) + ")";
        } else {
            msg_outtime.innerHTML = n[1] + "月" + n[2] + "日" + "(" + xq(next_days(get_intime, get_between)) + ")";
        }

    }

    //确定修改
    decide_day_btn.onclick = function () {
        day_msg_detail[2].innerHTML = get_between + "晚";
        msg.style.display = "none";
        //入住晚数改变提示
        msg_tip.style.display = "block";
        page_mask.style.display = "block";

        var s = next_days(get_intime, get_between);  //改变天数后的日期
        var n = s.split("/");
        if (n[1].length == 1) {
            day_msg_detail[1].innerHTML = "离店：" + "0" + n[1] + "月" + n[2] + "日";
        } else {
            day_msg_detail[1].innerHTML = "离店：" + n[1] + "月" + n[2] + "日";
        }
        paybar_price.innerHTML = room_price * get_between * rooms;		 //支付栏的金额
        msg_tip_price.innerHTML = "￥" + room_price * get_between * rooms;   //信息提示的金额
        msg_tip_ok.onclick = function () {
            close_all();
        }
    }
}

//用户须知
user_konw.onclick = function () {
    user_page.style.display = "block";
    /*关闭用户须知*/
    close_user_page.onclick = function () {
        user_page.style.display = "none";
    }
    user_page_mask.onclick = function () {
        user_page.style.display = "none";
    }
}

/*退出页面提示*/
exit_page_btn.onclick = function () {
    page_mask.style.display = "block";
    exit_page.style.display = "block";
    continue_btn.onclick = function () {
        close_all();
    }
};

//去支付
paybar_pay.onclick = function () {


    // self.location = encodeURI("pay_way.html?mod=pay&indate=" + get_intime + "&outdate=" + get_outtime + "&rooms=" + rooms + "&final_money=" + final_money); //编码

};



/*离开*/
exit_btn.onclick = function () {
    self.location = "hotel.php?mod=index"
};
	
